﻿using System;
using System.Collections.Generic;

namespace Aeon.Framework.Objects
{

/// <summary>
/// Text collection for easy handling.
/// Renders on unscaled orthogonal.
/// 
/// </summary>
public class Paragraph : IKey, IMove, IDraw
    {
    // --- Fields & Accessors:
    
    private String id;          public String ID       { get { return(id);     } }
    private Position origin;    public Position Origin { get { return(origin); } }

    private List<Text> lines;
    
    // --- Constructors:

    /// <summary>
    /// Agregator constructor for prepositioned Text objects of diverse styles.
    /// 
    /// </summary>
    public Paragraph(String key, List<Text> text)
        {
        Position pos = Position.Origin;
        
        init(key,pos,text);
        }

    /// <summary>
    /// Initializator constructor for new Text objects with the same style.
    /// 
    /// </summary>
    public Paragraph(String key, Position pos, List<String> text, IFont font)
        {
        List<Text> lst = new List<Text>();
        Single spc = font.Style.Size*1.1f;
        
        short cnt = 0;
        foreach(String s in text)
            {
            Text txt = new Text(key+"Line"+text.IndexOf(s),new Position(pos.xPos,pos.yPos+(-spc*cnt)/200,pos.zPos),font,s);
            lst.Add(txt);
            cnt++;
            }
        
        init(key,pos,lst);
        }
        
    // --- Internal Methods:        

    /// <summary>
    /// Actual chained constructor code.
    /// 
    /// </summary>
    private void init(String key, Position pos, List<Text> text)
        {
        id = key;
        origin = pos;
        lines = text;
        }

    // --- Interface Methods:

    public void Draw() { foreach(Text t in lines) { t.Draw(); } }
    
    public void MoveBy(IVector vec)
        {
        origin.Transform(vec);
        foreach(Text t in lines) { t.MoveBy(vec); }
        }

    public void MoveTo(Position pos) 
        {
        IVector distance = origin.Distance(pos);
        
        origin.Change(pos);
        foreach(Text t in lines) { t.MoveBy(distance); }
        }
            
    }


}